package com.ruoyi.web.controller.task;

import com.github.pagehelper.Page;
import com.github.pagehelper.page.PageParams;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.constant.HttpStatus;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.common.enums.BaseType;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.coretools.LanguageUtil;
import com.ruoyi.system.coretools.pay.PayUtils;
import com.ruoyi.system.coretools.pay.PayUtilsV2;
import com.ruoyi.system.domain.TDaoshi;
import com.ruoyi.system.domain.TFankui;
import com.ruoyi.system.domain.THelpCenter;
import com.ruoyi.system.domain.TUserInfo;
import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Api("用户中心管理")
@RestController
@RequestMapping("/api/task")
public class UserController extends BaseController {
    private static final Logger log = LoggerFactory.getLogger(UserController.class);

    @Resource
    UserService userService;
    @Resource
    private TokenService tokenService;
    @Resource
    ITBaseInfoService service;
    @Autowired
    private RedisCache redisCache;
    @Autowired
    PayUtilsV2 payUtils;
    @Resource
    ITUserInfoService itUserInfoService;
    @Resource
    ITUserInfoService userInfoService;
    @Resource
    private ITHelpCenterService tHelpCenterService;
    @Autowired
    private ITDaoshiService tDaoshiService;
    @Resource
    LanguageUtil languageUtil;
    @Autowired
    private ITFankuiService tFankuiService;
    @Autowired
    private RedisTemplate<String, String> redisTemplate;

    @ApiOperation("获取语言列表")
    @GetMapping("/getLangList")
    public AjaxResult getLangList() {
        AjaxResult result = userService.getLangList();
        return result;
    }

    @ApiOperation("首页轮播图")
    @GetMapping("/getHomeCarousel")
    public AjaxResult getHomeCarousel() {
        TBaseInfoDto baseInfoDto = new TBaseInfoDto();
        baseInfoDto.setType(BaseType.HOME_CAROUSEL.getType());
        baseInfoDto.setTypeLevel(BaseType.HOME_CAROUSEL.getTypeLevel());
        AjaxResult result = userService.getTaskBaseByCondition(baseInfoDto);
        return result;
    }

    @ApiOperation("首页-两个任务按钮")
    @GetMapping("/getHomeTaskType")
    public AjaxResult getHomeTaskType() {
        TBaseInfoDto baseInfoDto = new TBaseInfoDto();
        baseInfoDto.setType(BaseType.TASK_TYPE_HOME.getType());
        baseInfoDto.setTypeLevel(BaseType.TASK_TYPE_HOME.getTypeLevel());
        AjaxResult result = userService.getTaskBaseByCondition(baseInfoDto);
        return result;
    }

//    @ApiOperation("首页4个游戏标签")
//    @GetMapping("/getHomeGame")
//    public AjaxResult getHomeGame() {
//        TBaseInfoDto baseInfoDto = new TBaseInfoDto();
//        baseInfoDto.setType(BaseType.HOME_GAME.getType());
//        baseInfoDto.setTypeLevel(BaseType.HOME_GAME.getTypeLevel());
//        AjaxResult result = taskService.getTaskBaseByCondition(baseInfoDto);
//        return result;
//    }


    @ApiOperation("任务大厅的4个任务标签")
    @GetMapping("/getLobbyTaskByType")
    public AjaxResult getLobbyTaskByType() {
        TBaseInfoDto baseInfoDto = new TBaseInfoDto();
        baseInfoDto.setType(BaseType.TASK_TYPE_LOBBY.getType());
        baseInfoDto.setTypeLevel(BaseType.TASK_TYPE_LOBBY.getTypeLevel());
        AjaxResult result = userService.getTaskBaseByCondition(baseInfoDto);
        return result;
    }

    @ApiOperation("任务大厅的多个任务标签")
    @GetMapping("/getLobbyNextTaskByType")
    public AjaxResult getLobbyNextTaskByType() {
        TBaseInfoDto baseInfoDto = new TBaseInfoDto();
        baseInfoDto.setType(BaseType.TASK_TYPE_LOBBY_NEXT.getType());
        baseInfoDto.setTypeLevel(BaseType.TASK_TYPE_LOBBY.getTypeLevel());
        AjaxResult result = userService.getTaskBaseByCondition(baseInfoDto);
        return result;
    }


    @ApiOperation("首页-1-综合；2-新发布；3-价格；4-人气；5-图文任务")
    @PostMapping("/getHomeTaskByType")
    public AjaxResult getHomeTaskByType(@RequestBody ConditionReq req) {
        AjaxResult result = userService.getHomeTaskByType(req);
        return result;
    }


    @ApiOperation("查看任务详情")
    @PostMapping("/taskInfo")
    public AjaxResult taskInfo(@RequestBody ConditionReq req) {
        AjaxResult result = userService.taskInfo(req);
        return result;
    }


    @ApiOperation("换一个任务")
    @PostMapping("/exchangeTask")
    public AjaxResult exchangeTask(@RequestBody ConditionReq req) {
        AjaxResult result = userService.exchangeTask(req);
        return result;
    }


    @ApiOperation("接取任务")
    @PostMapping("/accessTask")
    public AjaxResult accessTask(@RequestBody ConditionReq req) {
        AjaxResult result = userService.accessTask(req);
        return result;
    }


    @ApiOperation("我的任务列表")
    @PostMapping("/userTaskList")
    public AjaxResult userTaskList(@RequestBody ConditionReq req) {
        AjaxResult result = userService.userTaskList(req);
        return result;
    }

    @ApiOperation("提交任务")
    @PostMapping("/submitTask")
    public AjaxResult submitTask(@RequestBody TTaskInfoDto req) {
        AjaxResult result = userService.submitTask(req);
        return result;
    }


    @ApiOperation("注册")
    @PostMapping("/userRegister")
    public AjaxResult userRegister(@RequestBody TUserRegisterInfoDto userRegisterInfoDto) {
        logger.info("收到注册请求{}", userRegisterInfoDto);
        TUserInfo result = userService.userRegister(userRegisterInfoDto);
        String appToken = tokenService.createAppToken(result);
        logger.info("完成注册请求{}", userRegisterInfoDto);
        return AjaxResult.success(appToken);
    }

    @ApiOperation("获取邮箱验证码")
    @PostMapping("/sendMailCodeToMail")
    public AjaxResult userRegisterMailCode(@RequestBody Map<String, Object> map) {
        logger.info("收到获取邮箱注册码请求{}", map);
        //后面做成配置
        if (map.get("email") == null) {
            throw new ServiceException("email不能为空");
        }
        AjaxResult result = userService.sendMailCodeToMail((String) map.get("email"));
        logger.info("完成获取邮箱注册码请求{}", result);
        return result;
    }

    @ApiOperation("设置修改个人信息")
    @PostMapping("/updateUserCenterUserInfo")
    public AjaxResult updateUserCenterUserInfo(@RequestBody Map<String, Object> map) {
        logger.info("收到修改个人信息请求{}", map);
        //过滤不能修改的信息
        TUserInfo tUserInfo = new TUserInfo();
        tUserInfo.setId(getUserInfoUserId());
        if ((map.get("userNick") != null)) {
            tUserInfo.setUserNick((String) map.get("userNick"));
        }
        if ((map.get("avatar") != null)) {
            tUserInfo.setAvatar((String) map.get("avatar"));
        }

        AjaxResult result = userService.updateUserInfo(tUserInfo);
        logger.info("完成修改个人信息请求{}", result);
        return result;
    }


    @ApiOperation("通过手机修改密码")
    @PostMapping("/updatePasswordByPhone")
    public AjaxResult updatePasswordByPhone(@RequestBody Map<String, Object> map) {
        logger.info("收到通过手机修改密码请求{}", map);
        //参数检查
        if (map.get("phone") == null) {
            throw new ServiceException("phone手机号不能为空");
        }
        if (map.get("phonecode") == null) {
            throw new ServiceException("phonecode手机验证码参数不能为空");
        }
        if (map.get("phoneWord") != null) {
            throw new ServiceException("phoneWord新的手机密码参数不能为空");
        }

        if (map.get("comfirmPhoneWord") != null) {
            throw new ServiceException("comfirmPhoneWord确认密码参数不能为空");
        }


        if (!map.get("phoneWord").toString().equals(map.get("comfirmPhoneWord").toString())) {
            throw new ServiceException("phoneWord与comfirmPhoneWord密码不一致,请确认确认密码与密码相同");
        }

        String phone = map.get("phone").toString();
        String redisMailCode = redisCache.getCacheMapValue("phonecodes", phone);
        if (!map.get("phonecode").toString().equals(redisMailCode)) {
            throw new ServiceException("手机验证码不正确,请重新发送验证码并提交修改。");
        }

        //通过邮箱查出原始数据并修改
        TUserInfo result = itUserInfoService.selectByPhone(phone);
        if (result == null) {
            throw new ServiceException("手机信息不存在,请确认手机输入是否正确。");
        }


        TUserInfo tUserInfo = new TUserInfo();
        tUserInfo.setId(result.getId());
        tUserInfo.setPhoneWord((String) map.get("emailWord"));


        AjaxResult ajaxResult = userService.updateUserInfo(tUserInfo);
        //业务完成后删除验证码
        redisCache.deleteCacheMapValue("phonecodes", phone);
        logger.info("完成通过手机修改密码请求{}", ajaxResult);
        return ajaxResult;
    }


    @ApiOperation("通过邮箱修改密码")
    @PostMapping("/updatePasswordByEmail")
    public AjaxResult updatePasswordByEmail(@RequestBody Map<String, Object> map) {
        logger.info("收到通过邮箱修改密码请求{}", map);
        //参数检查
        if (map.get("email") == null) {
            throw new ServiceException("email邮箱地址不能为空");
        }
        if (map.get("mailcode") == null) {
            throw new ServiceException("mailcode邮箱验证码参数不能为空");
        }
        if (map.get("emailWord") == null) {
            throw new ServiceException("emailWord新邮箱密码参数不能为空");
        }

        if (map.get("comfirmEmailWord") == null) {
            throw new ServiceException("comfirmEmailWord确认邮箱密码参数不能为空");
        }


        if (!map.get("emailWord").toString().equals(map.get("comfirmEmailWord").toString())) {
            throw new ServiceException("emailWord与comfirmEmailWord密码不一致,请确认确认密码与密码相同");
        }

        String email = map.get("email").toString();
        /*String redisMailCode = redisCache.getCacheMapValue("mailcodes", email);
        if (!map.get("mailcode").toString().equals(redisMailCode)) {
            throw new ServiceException("邮箱验证码不正确,请重新发送验证码并提交修改。");
        }*/

        //通过邮箱查出原始数据并修改
        TUserInfo result = itUserInfoService.selectByEmail(email);
        if (result == null) {
            throw new ServiceException("邮箱信息不存在,请确认邮箱输入是否正确。");
        }


        TUserInfo tUserInfo = new TUserInfo();
        tUserInfo.setId(result.getId());
        tUserInfo.setPhoneWord((String) map.get("emailWord"));


        AjaxResult ajaxResult = userService.updateUserInfo(tUserInfo);
        //业务完成后删除验证码
        redisCache.deleteCacheMapValue("mailcodes", email);
        logger.info("完成通过邮箱修改密码请求{}", ajaxResult);
        return ajaxResult;
    }


    @ApiOperation("登录")
    @PostMapping("/userLogin")
    public AjaxResult userLogin(@RequestBody TUserInfoDto userInfoDto) {
        TUserInfo result = userService.userLogin(userInfoDto);
        String appToken = tokenService.createAppToken(result);
        return AjaxResult.success(appToken);
    }


    @ApiOperation("个人中心")
    @GetMapping("/getUserInfo")
    public AjaxResult getUserInfo() {
        AjaxResult result = userService.getUserInfo();
        return result;
    }

    @ApiOperation("我的钱包")
    @GetMapping("/getUserMoney")
    public AjaxResult getUserMoney() {
        AjaxResult result = userService.getUserMoney();
        return result;
    }

    @ApiOperation("我的钱包-收益明细")
    @PostMapping("/getUserEarningsList")
    public AjaxResult getUserEarningsList(@RequestBody TTaskInfoDto req) {
        req.setMoneyDetailType(1);
        Integer earningsType = req.getEarningsType();
        if (earningsType == null) {
            throw new ServiceException("收益类型不能为空");
        }
        AjaxResult result = userService.getUserEarningsList(req);
        return result;
    }

    @ApiOperation("我的钱包-提现明细")
    @PostMapping("/getUserWithdrawList")
    public AjaxResult getUserWithdrawList(@RequestBody TTaskInfoDto req) {
        req.setMoneyDetailType(3);
        req.setEarningsType(null);
        AjaxResult result = userService.getUserEarningsList(req);
        return result;
    }

    @ApiOperation("我的钱包-充值明细")
    @PostMapping("/getUserTopUpList")
    public AjaxResult getUserTopUpList(@RequestBody TTaskInfoDto req) {
        req.setMoneyDetailType(5);
        req.setEarningsType(null);
        AjaxResult result = userService.getUserEarningsList(req);
        return result;
    }


    @ApiOperation("个人任务订单统计")
    @GetMapping("/getUserTaskListStatistics")
    public AjaxResult getUserTaskListStatistics() {
        AjaxResult result = userService.getUserTaskListStatistics();
        return result;
    }

    @ApiOperation("个人中心轮播图")
    @GetMapping("/getUserCarousel")
    public AjaxResult getUserCarousel() {
        TBaseInfoDto baseInfoDto = new TBaseInfoDto();
        baseInfoDto.setType(BaseType.USER_CAROUSEL.getType());
        baseInfoDto.setTypeLevel(BaseType.USER_CAROUSEL.getTypeLevel());
        AjaxResult result = userService.getTaskBaseByCondition(baseInfoDto);
        return result;
    }

    @ApiOperation("我的团队")
    @GetMapping("/userTeam")
    public AjaxResult userTeam() {
        AjaxResult result = userService.userTeam();
        return result;
    }

    @ApiOperation("上传图片")
    @PostMapping("/uploadImg")
    public AjaxResult uploadImg(MultipartFile file) throws IOException {
        String upload = FileUploadUtils.upload(file);
        return AjaxResult.success(upload);
    }


    @ApiOperation("会员详情-各层级的会员")
    @PostMapping("/memberList")
    public AjaxResult memberList(@RequestBody TTaskInfoDto req) {
        Integer level = req.getLevel();
        if (level == null) {
            throw new ServiceException("查看会员详情列表-等级数据不能为空");
        }
        AjaxResult result = userService.memberList(req);
        return result;
    }

    @ApiOperation("我的-会员升级-会员列表")
    @GetMapping("/vipList")
    public AjaxResult vipList() {
        AjaxResult result = userService.vipList();
        return result;
    }

    @ApiOperation("我的-会员升级-购买会员")
    @GetMapping("/vipBuy")
    public AjaxResult vipBuy(@RequestParam("id") Long id) {
        if (id == null) {
            throw new ServiceException("会员id不能为空");
        }
        AjaxResult result = userService.vipBuy(id);
        return result;
    }


    @ApiOperation("活动-签到")
    @GetMapping("/userSignList")
    public AjaxResult userSignList() {
        AjaxResult result = userService.userSignList();
        return result;
    }


    @ApiOperation("活动-当日签到")
    @GetMapping("/userSign")
    public AjaxResult userSign() {
        AjaxResult result = userService.userSign();
        return result;
    }

    @ApiOperation("活动-获取抽奖奖品")
    @GetMapping("/turntableList")
    public AjaxResult turntableList() {
        AjaxResult result = userService.turntableList();
        return result;
    }

    @ApiOperation("活动-获取抽奖奖品")
    @GetMapping("/getTurntable")
    public AjaxResult getTurntable(@RequestParam(value = "id", required = false) Long id) {
        AjaxResult result = userService.getTurntable(id);
        return result;
    }
    @ApiOperation("抽奖活动-中奖记录")
    @GetMapping("/getTurntableLog")
    public AjaxResult getTurntableLog(@RequestParam(value = "pageSize") Integer pageSize,@RequestParam(value = "pageNum") Integer pageNum) {
        AjaxResult result = userService.getTurntableLog(pageSize,pageNum);
        return result;
    }


    @ApiOperation("抽奖活动-抽奖任务和次数")
    @GetMapping("/getTaskAndNum")
    public AjaxResult getTaskAndNum() {
        AjaxResult result = userService.getTaskAndNum();
        return result;
    }

    /**
     * 前端调用充值接口
     */
    /**
     * 充值回调
     *
     * @param jsonParam float类型 amount金额必传
     * @return
     */
    @PostMapping("/chongZhi")
    public AjaxResult chongZhi(@RequestBody Map<String, Object> jsonParam) {
        log.info("收到前端充值请求:{}", jsonParam);

        try {

            if (jsonParam.get("amount") == null) {
                return AjaxResult.error("amount参数不能为空");
            }
            float amount = Float.parseFloat(jsonParam.get("amount").toString());
            if (amount <= 0) {
                return AjaxResult.error("amount参数不能小于等于0");
            }


            String payUrl = payUtils.createChongzhiOrder(getUserInfoUserId(), amount);
            Map resultMap = new HashMap();
            resultMap.put("payUrl", payUrl);

            log.info("结束前端充值请求:{}", jsonParam);
            //返回收银地址
            return AjaxResult.success(resultMap);
        } catch (Exception e) {
            e.printStackTrace();
            //这个Exception在全局异常处理里面要吃掉，必须跑出去让发起回调放知晓。
            log.info("充值失败", jsonParam);
            //框架会自动处理异常返回错误消息
            throw new ServiceException(e.getMessage(), HttpStatus.ERROR);
        }

    }


    /**
     * string类型 address_user必传
     * float类型 amount金额必传
     * 前端提现接口
     */
    @PostMapping("/tixian")
    public AjaxResult tiXian(@RequestBody Map<String, Object> jsonParam) {
        log.info("收到前端提现请求:{}", jsonParam);
        ISysConfigService configService = SpringUtils.getBean(ISysConfigService.class);
        try {
            //提现时间参数检查
            ZonedDateTime now = ZonedDateTime.now();
            //英国格林威治时间检查
            ZonedDateTime gmtTime = now.withZoneSameInstant(ZoneId.of("Europe/London"));
            String tixian_allow_startTime = configService.selectConfigByKey("tixian_allow_startTime");
            String tixian_allow_endTime = configService.selectConfigByKey("tixian_allow_endTime");
            int startTimeHour=Integer.parseInt(tixian_allow_startTime.split(":")[0]);
            int endTimeHour=Integer.parseInt(tixian_allow_endTime.split(":")[0]);
            log.info("当前时间是英国格林威治时间:{}",gmtTime.toString());
            if(!(gmtTime.getHour()>=startTimeHour&&gmtTime.getHour()<endTimeHour)){
                return AjaxResult.error("当前时间不在不在英国英国格林威治提现时间范围内:"+startTimeHour+"-"+endTimeHour);
            }


            //redis每天调用次数检查
            String key="tixian_"+getUserInfoUserId()+"_count";
            boolean existsFlag = this.redisTemplate.opsForValue().setIfAbsent(key, String.valueOf(1),1, TimeUnit.DAYS);
            if(!existsFlag) {
                //存在做检查
                Integer bindedDailyCounts = Integer.valueOf(redisTemplate.opsForValue().get(key));
                if(bindedDailyCounts>=Integer.parseInt(configService.selectConfigByKey("tixian_maxCount"))){
                    throw new ServiceException("此用户今日提现次数已经超限:"+configService.selectConfigByKey("tixian_maxCount"),HttpStatus.ERROR);
                }
                this.redisTemplate.opsForValue().increment(key, 1);//bindedDailyCounts +
            }





            //参数校验
            if (jsonParam.get("payWord") == null) {
                return AjaxResult.error("payWord支付密码参数不能为空");
            }

            if (jsonParam.get("addressUser") == null) {
                return AjaxResult.error("addressUser参数不能为空");
            }

            if (jsonParam.get("amount") == null) {
                return AjaxResult.error("amount参数不能为空");
            }
            float amount = Float.parseFloat(jsonParam.get("amount").toString());
            if (amount <= 0) {
                return AjaxResult.error("amount参数不能小于等于0");
            }


            String payWord = (String) jsonParam.get("payWord");
            TUserInfoDto userInfo = userInfoService.getUserById(getUserInfoUserId());
            if (!payWord.equals(userInfo.getPayWord())) {
                return AjaxResult.error("支付密码错误");
            }


            String addressUser = (String) jsonParam.get("addressUser");


            boolean requestResult = payUtils.createTiXianOrder(getUserInfoUserId(), amount, addressUser);


            log.info("结束前端提现请求:{} 请求结果:{}", jsonParam, requestResult);
            if (requestResult == true) {
                return AjaxResult.success();
            } else {
                return AjaxResult.error();
            }
        } catch (Exception e) {
            e.printStackTrace();
            //这个Exception在全局异常处理里面要吃掉，必须跑出去让发起回调放知晓。
            log.info("提现失败:{}", jsonParam);
            throw new ServiceException(e.getMessage(), HttpStatus.ERROR);
        }

    }

    /**
     * 修改提现密码
     *
     * @param jsonParam
     * @return
     */
    @PostMapping("/tixianWordChage")
    public AjaxResult tixianWordChage(@RequestBody Map<String, Object> jsonParam) {
        log.info("收到前端修改提现密码请求:{}", jsonParam);

        try {
            //参数校验
            if (jsonParam.get("payWord") == null) {
                return AjaxResult.error("payWord支付密码参数不能为空");
            }

            //参数校验
            if (jsonParam.get("confimPayWord") == null) {
                return AjaxResult.error("确认confimPayWord支付密码参数不能为空");
            }


            if (!jsonParam.get("payWord").equals(jsonParam.get("confimPayWord"))) {
                return AjaxResult.error("确认密码与支付密码不一致请检查输入是否正确");
            }

            //修改支付密码
            TUserInfo tUserInfo = new TUserInfo();
            tUserInfo.setId(getUserInfoUserId());
            tUserInfo.setPayWord(jsonParam.get("payWord").toString());
            userInfoService.updateById(tUserInfo);
            log.info("结束前端修改提现密码请求:{}", jsonParam);
            return AjaxResult.success();

        } catch (Exception e) {
            e.printStackTrace();
            //这个Exception在全局异常处理里面要吃掉，必须跑出去让发起回调放知晓。
            log.info("修改支付密码失败:{}", jsonParam);
            return AjaxResult.error();
        }

    }


    /**
     * 提现参数表参数查询
     *
     * @return
     */
    @GetMapping("/tixianParamQuery")
    public AjaxResult tixianParamQuery() {
        log.info("收到提现参数表参数查询请求");

        ISysConfigService configService = SpringUtils.getBean(ISysConfigService.class);
        String embodyMoney = configService.selectConfigByKey("embodyMoney");
        String vipEmbodyMoney = configService.selectConfigByKey("vipEmbodyMoney");
        String tixian_maxCount = configService.selectConfigByKey("tixian_maxCount");
        String tixian_lowAmount = configService.selectConfigByKey("tixian_lowAmount");
        String tixian_allow_startTime = configService.selectConfigByKey("tixian_allow_startTime");
        String tixian_allow_endTime = configService.selectConfigByKey("tixian_allow_endTime");

        JSONObject jsonObject=new JSONObject();
        jsonObject.put("embodyMoney",embodyMoney);
        jsonObject.put("tixian_maxCount",tixian_maxCount);
        jsonObject.put("tixian_lowAmount",tixian_lowAmount);
        jsonObject.put("tixian_allow_startTime",tixian_allow_startTime);
        jsonObject.put("tixian_allow_endTime",tixian_allow_endTime);
        jsonObject.put("vipEmbodyMoney",vipEmbodyMoney);


        log.info("结束提现参数表参数查询请求");
        return AjaxResult.success(jsonObject);


    }


    /**
     * 不分页查询帮助中心列表前台接口
     */
    @GetMapping("/applist")
    public AjaxResult applist(THelpCenter tHelpCenter) {
        String extendField1 = tHelpCenter.getExtendField1();
        if (StringUtils.isEmpty(extendField1)) {
            throw new ServiceException("协议编码不能为空");
        }
        logger.info("收到app查询帮助中心文章列表请求");
        List<THelpCenter> list = tHelpCenterService.selectTHelpCenterList(tHelpCenter);
        logger.info("结束app查询帮助中心文章列表请求");
        languageUtil.LanguageValue(list);
        return AjaxResult.success(list.get(0));
    }


    @GetMapping("/shareGift")
    public AjaxResult shareGift() {
        THelpCenter tHelpCenter = new THelpCenter();
        tHelpCenter.setExtendField1("fxst");
        List<THelpCenter> list = tHelpCenterService.selectTHelpCenterList(tHelpCenter);
        logger.info("结束app查询帮助中心文章列表请求");
        languageUtil.LanguageValue(list);
        return AjaxResult.success(list.get(0));
    }

    @GetMapping("/business")
    public AjaxResult business() {
        THelpCenter tHelpCenter = new THelpCenter();
        tHelpCenter.setExtendField1("swhz");
        List<THelpCenter> list = tHelpCenterService.selectTHelpCenterList(tHelpCenter);
        logger.info("结束app查询帮助中心文章列表请求");
        languageUtil.LanguageValue(list);
        return AjaxResult.success(list.get(0));
    }


    /**
     * 前台新增联系人方式（联系人方式,放我的导师那儿）
     */
    @PostMapping("/app/daoshi/addContent")
    public AjaxResult add(@RequestBody TDaoshi tDaoshi)
    {
        //参数后台取，防止注入
        tDaoshi.setUserId(getUserInfoUserId());
        return toAjax(tDaoshiService.insertTDaoshi(tDaoshi));
    }
    /**
     * 修改联系信息
     */
    @PostMapping("/app/daoshi/daoshiEdit")
    public AjaxResult daoshiEdit(@RequestBody TDaoshi tDaoshi)
    {
        //参数后台取，防止注入
        tDaoshi.setUserId(getUserInfoUserId());
        return toAjax(tDaoshiService.updateTDaoshi(tDaoshi));
    }

    /**
     * 删除联系信息
     */
    @DeleteMapping("/app/daoshi/{ids}")
    public AjaxResult daoshiRemove(@PathVariable Long[] ids)
    {
        return toAjax(tDaoshiService.deleteTDaoshiByIds(ids));
    }




    /**
     * 前台查询联系人方式
     */
    @GetMapping("/app/list")
    public AjaxResult applist(TDaoshi tDaoshi)
    {
        //参数后台取，防止注入
        tDaoshi.setUserId(getUserInfoUserId());
        logger.info("查到查询我的导师的请求");
        List<TDaoshi> list = tDaoshiService.selectTDaoshiList(tDaoshi);
        logger.info("结束查询我的导师的请求");
        return AjaxResult.success(list);
    }


    /**
     * 前台查询我的导师联系人方式（联系人方式,放我的导师那儿）
     */
    @GetMapping("/app/daoshi/list")
    public AjaxResult daoshiApplist()
    {

        Long userId=getUserInfoUserId();

        TUserInfo tUserInfoResult=itUserInfoService.selectTUserInfoById(userId);
        if(tUserInfoResult!=null&&tUserInfoResult.getParentId()!=null) {
            log.info("上级:{}",tUserInfoResult);
          Long parentId=  tUserInfoResult.getParentId();
            TDaoshi tDaoshi=new TDaoshi();

            //参数后台取，防止注入
            tDaoshi.setUserId(parentId);
            logger.info("查到查询我的导师的请求");
            List<TDaoshi> list = tDaoshiService.selectTDaoshiList(tDaoshi);
            log.info("导师几条:{}",list.size());
            logger.info("结束查询我的导师的请求");

            return AjaxResult.success(list);
        }else {
            return AjaxResult.success();
        }


    }

    /**
     * 新增意见反馈(前台接口)
     */
    @PostMapping("/system/fankui/api/add")
    public AjaxResult apiadd(@Validated @RequestBody TFankui tFankui)
    {
        //补充用户信息
        tFankui.setUserId(getUserInfoUserId());
        return toAjax(tFankuiService.insertTFankui(tFankui));
    }

    /**
     * 获取新手任务和完成状态
     * @return
     */
    @GetMapping("/fistJob")
    public AjaxResult fistJob()
    {
        logger.info("查看新手任务和完成状态");
        return userService.fistJob();

    }

}
